import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import routes from './routeconfig'
// const router = createRouter({
//   history: createWebHistory(import.meta.env.BASE_URL),
//   routes
// })
const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes

})
//设置 全局前置路由守卫
router.beforeEach((to, from, next) => {

  // nProgress.start();//开始播放进度条动画

  // to 将要去的路由对象
  // from 来自哪的路由对象
  //判断当前路由是否是 购物车,我的 两个路由
  //判断当前用户是否登陆
  var accessRoutes = ['/home/bureauschool', '/index/homes', '/home/homeschool', '/home/messagestatistics', '/home/userstatistics', '/home/schoolstatistics', '/pingjiafabu',
    '/kaoqin',
    '/index',
    '/editnotification',
    '/myphoto',
    '/publishphoto',
    '/massagebureau',
    '/sendreminders',
    '/kaoqin',
    '/home/schoolstatistics/sg'];
  var token = localStorage.getItem('useinfo');

  if (accessRoutes.includes(to.path)) { //判断当前路由是否是 购物车,我的 两个路由中的一个
    if (token) { // 判断当前用户是否登陆
      next();//允许访问
    } else {
      next('/logins');
    }
  } else { //访问的是其他路由
    next();
  }
})
export default router
